package interfaces.lunchy;

import java.io.*;
import java.util.*;
/**
 *
 * @author
 */
public class PropIni {
    
    /** Creates a new instance of PropIni */
    private String FileName;
    
    public PropIni(String FileName) {
        this.FileName = FileName;
    }
    public void ExistsFile()throws IOException {
        File f = new File(FileName);
        if(!f.exists()){
            if(f.createNewFile())
            	System.out.println("create");
        }
    }
    public void WriteString(String key, String value){
        try{
           Properties p = new Properties();
           ExistsFile();
           p.load(new FileInputStream(FileName));
           //p.list(System.out);
           p.put(key, value);
           FileOutputStream out = new FileOutputStream(FileName);
           p.save(out, "/*properties*/");
           out.close();
        }
        catch(Exception e){
             
        }
    }
    

    public String ReadString(String key){
        String value=null;
        try{
            
            Properties p = new Properties();
            ExistsFile();
            p.load(new FileInputStream(FileName));
            value = p.getProperty(key);
            
        }
        catch(Exception e){
          
           
        }
        return value;
    }
    public int ReadInt(String key){
         int value=0;
        try {
            ExistsFile();
            Properties p = new Properties();
            p.load(new FileInputStream(FileName));
            value = Integer.valueOf(p.getProperty(key)!=null ? p.getProperty(key) : Integer.toString(0));
        } catch (IOException ex) {

        }
         return value;
    }
}